package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.AlbumPhotoDTO;
import com.andy.blog.admin.service.AlbumPhotoBusService;
import com.andy.blog.common.annotation.Log;
import com.andy.blog.common.enums.BusinessTypeEnum;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.vo.AlbumPhotoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by andy on 2024/4/2 12:24
 **/
@RestController
@Api(tags = "相册照片")
public class AlbumPhotoController {

    @Resource
    private AlbumPhotoBusService albumPhotoBusService;

    /**
     * 查看相册照片列表
     */
    @ApiOperation(value = "查看相册照片列表")
    @GetMapping("/albumPhoto/list")
    public GeneralResponseResult<List<AlbumPhotoDTO>> listAlbumVO() {
        return GeneralResponseResult.success(albumPhotoBusService.selectList());
    }

    /**
     * 获取上级相册
     */
    @GetMapping("/albumPhoto/listByParent")
    public GeneralResponseResult<List<AlbumPhotoDTO>> listByParent() {
        return GeneralResponseResult.success(albumPhotoBusService.listByParent());
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('portal:photo:add')")
    @Log(title = "相册管理", businessType = BusinessTypeEnum.INSERT)
    @PostMapping("/albumPhoto/add")
    public GeneralResponseResult<Void> add(@Validated @RequestBody AlbumPhotoVO albumPhotoVO) {
        albumPhotoBusService.add(albumPhotoVO);
        return GeneralResponseResult.success();
    }

    /**
     * 查询详细
     */
    @GetMapping(value = "/albumPhoto/{id}")
    public GeneralResponseResult<AlbumPhotoDTO> getById(@PathVariable Long id) {
        return GeneralResponseResult.success(albumPhotoBusService.selectById(id));
    }


    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:senive:edit')")
    @Log(title = "修改", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping("/albumPhoto")
    public GeneralResponseResult<Void> edit(@Validated @RequestBody AlbumPhotoVO albumPhotoVO) {
        albumPhotoBusService.updateById(albumPhotoVO);
        return GeneralResponseResult.success();
    }


    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('portal:ablum:remove')")
    @Log(title = "相册管理", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/albumPhoto/{id}")
    public GeneralResponseResult<Void> remove(@PathVariable Long id) {
        albumPhotoBusService.deleteById(id);
        return GeneralResponseResult.success();
    }
}
